package com.pro.common.service.user.mq;


import com.pro.common.api.CommonConst;
import com.pro.common.api.model.dto.UserAmountDTO;
import com.pro.common.service.user.service.UserAmountService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
@Slf4j
public class UserAmountUpdateMqConsumer {

    // 注入需要的服务
    private final UserAmountService userAmountService;

    @RabbitListener(queues = CommonConst.RoutingKey_Queue.userAmount_saveOrUpdate)
    public void saveOrUpdateUserAmountDTO(List<UserAmountDTO> userAmountDTOS) {
        try {
            userAmountService.saveOrUpdateUserAmountDTO(userAmountDTOS);
        } catch (Exception e) {
            log.error("更新用户存储信息失败：{}", e.getMessage(), e);
            throw e;
        }
    }
}
